<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Device extends BaseModel
{
    protected $name = 'device';

    //设备类型:1风机;2温度传感器;3空调;4电表;5一体机
    const DEVICE_TYPE_FJ = 1;
    const DEVICE_TYPE_CGQ = 2;
    const DEVICE_TYPE_KT = 3;
    const DEVICE_TYPE_DB = 4;
    const DEVICE_TYPE_YTJ = 5;
    const DEVICE_TYPE_JK = 6;
    const DEVICE_TYPE_PLC = 7;

    public static function types(): array
    {
        return [
            self::DEVICE_TYPE_FJ => '风机',
            self::DEVICE_TYPE_CGQ => '传感器',
            self::DEVICE_TYPE_KT => '空调',
            self::DEVICE_TYPE_DB => '电表',
            self::DEVICE_TYPE_YTJ => '一体机',
            self::DEVICE_TYPE_JK => '监控',
            self::DEVICE_TYPE_PLC => 'PLC',
        ];
    }

    /**
     * 同步的信息
     * @return \think\model\relation\HasOne
     */
    public function sync(): \think\model\relation\HasOne
    {
        return $this->hasOne(DeviceSync::class, 'serial_no', 'serial_no');
    }

    public function stock(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(StockDevice::class, 'id', 'device_id');
    }
}
